草庐IT

iphone - int、NSInteger 和 NSUInteger 的区别

全部标签

c# - 如何获取 Int 数组中最常见的值? (C#)

如何使用C#获取Int数组中最常见的值例如:数组有以下值:1,1,1,2答案应该是1 最佳答案 varquery=(fromiteminarraygroupitembyitemintogorderbyg.Count()descendingselectnew{Item=g.Key,Count=g.Count()}).First();只为值(value)而不是计数,你可以这样做varquery=(fromiteminarraygroupitembyitemintogorderbyg.Count()descendingselectg.Ke

c# 对 List<KeyValuePair<int, string>> 进行排序

在C#中,我想对List>进行排序按列表中每个字符串的长度。在Psuedo-Java中,这将是匿名的,看起来像这样:Collections.Sort(someList,newComparator>({publicintcompare(KeyValuePairs1,KeyValuePairs2){return(s1.Value.Length>s2.Value.Length)?1:0;//specifymysortingcriteriahere}});如何获得上述功能? 最佳答案 C#中的等效项是使用lambda表达式和Sort方法:s

c# - 这两种声明数组的方式有什么区别?

这个问题在这里已经有了答案:WhatarethedifferencesbetweenamultidimensionalarrayandanarrayofarraysinC#?(12个答案)关闭1年前。有什么区别:int[][]myArray;和int[,]myOtherArray;

c# - 从 double 转换为 int 的最佳(最安全)方法

我很好奇将double转换为整数的最佳方法。运行时安全是我在这里的主要关注点(它不一定是最快的方法,但这是我的次要关注点)。我在下面留下了一些我可以想出的选项。任何人都可以权衡哪种是最佳实践吗?有没有我没有列出的更好的方法来完成这个?doublefoo=1;intbar;//Option1boolparsed=Int32.TryParse(foo.ToString(),outbar);if(parsed){//...}//Option2bar=Convert.ToInt32(foo);//Option3if(fooInt32.MinValue){bar=(Int32)foo;}

c# - "private"和 "protected Internal"有什么区别?

我只想知道private和protectedinternal访问说明符之间的实际区别是什么。据我所知Visibletoownclassmembers:privateandprotectedinternalYESVisibletoobjectofotherclasses:BothNOVisibletoobjectsofotherclassesoutsidethenamespacecollection:BothNOVisibletoobjectofchildclassesoutsidethenamespacecollection:BothNO如果private与protectedinter

c# - String.Empty 和 “” 和 null 有什么区别?

这个问题在这里已经有了答案:关闭13年前。PossibleDuplicate:WhatisthedifferencebetweenString.Emptyand“”""是否等同于String.Empty?哪个是初始化字符串值的首选?

c# - 将 int 1、10、100 格式化为字符串 "001"、 "010"、 "100"的掩码

我如何将掩码应用于字符串以按以下方式格式化输出文本(最多2个前导零):inta=1,b=10,c=100;stringaF=LeadingZeroFormat(a),bF=LeadingZeroFormat(b),cF=LeadingZeroFormat(c);Console.Writeline("{0},{1},{2}",aF,bF,cF);//"001,010,100"什么是最优雅的解决方案?提前致谢。 最佳答案 您可以使用Int32.ToString("000")以这种方式格式化整数。有关详细信息,请参阅CustomNumer

c# - 背靠背 for 循环中的 int、short、byte 性能

(背景:WhyshouldIuseintinsteadofabyteorshortinC#)为了满足我自己对使用“适当大小”整数与“优化”整数的优缺点的好奇心,我编写了以下代码,这些代码强化了我之前对.Net中的int性能的看法(并对此进行了解释在上面的链接中)这是针对int性能而不是short或byte进行了优化。DateTimet;longa,b,c;t=DateTime.Now;for(intindex=0;index这在......方面给出了大致一致的结果~950000~2000000~1700000这符合我的预期。然而,当我尝试像这样为每种数据类型重复循环时......t=D

c# - 如何将 List<String> 转换为 Dictionary<int,String>

我有List,我需要将其转换为Dictionary自动生成key,有什么最短的方法可以实现吗?我试过:vardictionary=newDictionary();intindex=0;list.ForEach(x=>{definitions.Add(index,x);index++;});但我认为这是肮脏的方式。 最佳答案 vardict=list.Select((s,i)=>new{s,i}).ToDictionary(x=>x.i,x=>x.s); 关于c#-如何将List转换为Di

c# - 了解使用固定{}、Marshal.AllocHGlobal() 和 GCHandle.Alloc() 之间的区别

首先我要说的是,我在整个论坛和网络上的许多链接中查看并找到了有关使用fixed{}、Marshal.AllocHGlobal()和GCHandle.Alloc()的描述。但是,我还没有找到关于何时使用Marshal类与GCHandle类(使用和不使用fixed{})的简明解释。我正在使用第三方.NET库,它在“Buffer”类中有一个名为Readline()的方法。手册显示了以下函数原型(prototype):boolReadLine(intx1,inty1,intx2,inty2,System.IntPtrbufData,outintnumRead);bufData的描述如下:...